;(function($){   
                $.fn.extend({   
                    marquee:function(o)
                    {   
                        o = $.extend({
                            speed       :30,        //滚动的速度
                            step        :1,         //滚动的步长 
                            direction   :'up',      //滚动的方向,left,right,up,down
                            pause       :0,       //停顿的时间
                            autoEle:"ul",
                            autoChild:"li",
                            autoStatic:false
                        }, o || {});
                        //alert(o.direction);
                        var dIndex = jQuery.inArray(o.direction, ['right', 'down']);
                        if (dIndex > -1) {
                            o.direction = ['left', 'up'][dIndex];
                            o.step = -o.step;
                        }
                        var mid;
                        var div         = $(this); // 容器对象
                        var divWidth    = div.innerWidth(); // 容器宽
                        var divHeight   = div.innerHeight(); // 容器高
                        var ul          = $(o.autoEle, div);
                        var li          = $(o.autoChild, ul);
                        ul.append(li.clone()); // 复制元素
                        var liHeight    = li.height(); // 元素高
                        var height      = liHeight * liSize;
                        var liSize  = $(this).find(o.autoChild).size() // append元素个数
                        var liWidth = li.width(); // 元素宽
                        var width= liWidth * liSize;
                        var _initWidth=width*0.5;
                        if ((o.direction == 'left') || (o.direction == 'up' && height > divHeight)) 
                        {
                            // 元素超出可显示范围才滚动
                            if (o.direction == 'left') 
                            {
                                ul.width(2*liSize * liWidth);
                                if (o.step < 0) div.scrollLeft(width);
                            }
                            else 
                            {
                                ul.height(2 * liSize * liHeight);
                                if (o.step < 0) div.scrollTop(height);
                            }
                            //默认不是静态的，则动，反之，默认为静态的。滑过去则动
                            if(o.autoStatic===false){
                                mid = setInterval(_marquee, o.speed);
                                div.hover(
                                    function(){clearInterval(mid);},
                                    function(){mid = setInterval(_marquee, o.speed);}
                                );
                            }else{
                                div.hover(
                                    function(){mid = setInterval(_marquee, o.speed);},
                                    function(){clearInterval(mid);}
                                );
                            }
                        }
                        function _marquee() {
                            // 滚动
                            if (o.direction == 'left') {
                                var l = div.scrollLeft();
                                if (o.step < 0) {
                                    div.scrollLeft((l <= 0 ? _initWidth : l) + o.step);
                                } else {
                                    if(l >= _initWidth){
                                         l=0;
                                    }else{
                                        l+=o.step;
                                    }
                                    div.scrollLeft(l);
                                }
                                if (l % liWidth == 0) _pause();
                            } else {
                                var t = div.scrollTop();
                                if (o.step < 0) {
                                    div.scrollTop((t <= 0 ? height : t) + o.step);
                                } else {
                                    div.scrollTop((t >= height ? 0 : t) + o.step);
                                }
                                if (t % liHeight == 0) _pause();
                            }
                        }
                        function _pause() {
                            // 停顿
                            if (o.pause > 0) {
                                var tempStep = o.step;
                                o.step = 0;
                                setTimeout(function() {
                                    o.step = tempStep;
                                }, o.pause);
                            }
                        }
                    }
                });          
                })(jQuery);